package com.jinmei.utils;

import java.net.URLDecoder;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

import com.jinmei.model.Employee;

public class SysncEmployeeActionUtil {

	public static Employee convertRequestPar2Employee(HttpServletRequest request, Employee employee) throws Exception{
		if(request.getParameter("FID") != null){
			employee.setfId(Integer.valueOf(URLDecoder.decode(request.getParameter("FID"), JinmeiConsts.ENCODING)));
		}
		if(request.getParameter("FNumber") != null){
			employee.setfNumber(URLDecoder.decode(request.getParameter("FNumber"), JinmeiConsts.ENCODING));
		}
		if(request.getParameter("FName") != null){
			employee.setfName(URLDecoder.decode(request.getParameter("FName"), JinmeiConsts.ENCODING));
		}
		if(request.getParameter("FFullName") != null){
			employee.setfFullName(URLDecoder.decode(request.getParameter("FFullName"), JinmeiConsts.ENCODING));
		}
		if(request.getParameter("FEnName") != null){
			employee.setfEnName(URLDecoder.decode(request.getParameter("FEnName"), JinmeiConsts.ENCODING));
		}
		if(request.getParameter("FNick") != null){
			employee.setfNick(URLDecoder.decode(request.getParameter("FNick"), JinmeiConsts.ENCODING));
		}
		if(request.getParameter("FSex") != null){
			employee.setfSex(FSex.getFSexStr(
					URLDecoder.decode(request.getParameter("FSex"), JinmeiConsts.ENCODING)));
		}
		if(request.getParameter("FBirthDay") != null){
			employee.setfBirthday(StringUtil.convertString2Date(URLDecoder.decode(request.getParameter("FBirthDay"), JinmeiConsts.ENCODING)));
		}
		if(request.getParameter("FIDNum") != null){
			employee.setfIdNum(URLDecoder.decode(request.getParameter("FIDNum"), JinmeiConsts.ENCODING));
		}
		if(request.getParameter("FEntryDate") != null){
			employee.setfEntryDate(StringUtil.convertString2Date(URLDecoder.decode(request.getParameter("FEntryDate"), JinmeiConsts.ENCODING)));
		}
		if(request.getParameter("FLeaveDate") != null){
			employee.setfLeaveDate(StringUtil.convertString2Date(URLDecoder.decode(request.getParameter("FLeaveDate"), JinmeiConsts.ENCODING)));
		}
		if(request.getParameter("FPMobile") != null){
			employee.setfPMobile(URLDecoder.decode(request.getParameter("FPMobile"), JinmeiConsts.ENCODING));
		}
		if(request.getParameter("FMobile") != null){
			employee.setfMobile(URLDecoder.decode(request.getParameter("FMobile"), JinmeiConsts.ENCODING));
		}
		if(request.getParameter("FTel") != null){
			employee.setfTel(URLDecoder.decode(request.getParameter("FTel"), JinmeiConsts.ENCODING));
		}
		if(request.getParameter("FEmail") != null){
			employee.setfEmail(URLDecoder.decode(request.getParameter("FEmail"), JinmeiConsts.ENCODING));
		}
		if(request.getParameter("FAddress") != null){
			employee.setfAddress(URLDecoder.decode(request.getParameter("FAddress"), JinmeiConsts.ENCODING));
		}
		if(request.getParameter("FVirCode") != null){
			employee.setfVirCode(URLDecoder.decode(request.getParameter("FVirCode"), JinmeiConsts.ENCODING));
		}
		if(request.getParameter("FDeptId") != null){
			employee.setfDeptId(Integer.valueOf(URLDecoder.decode(request.getParameter("FDeptId"), JinmeiConsts.ENCODING)));
		}
		return employee;
	}
	
	static enum FSex {
		MALE("1", "男"),
		FEMALE("2", "女"),
		OTHER("0", "");
		
		String type;
		String value;
		
		FSex(String type, String value) {
			this.type = type;
			this.value = value;
		}
		
		static String getFSexStr(String type) {
			return StringUtils.equals(type, MALE.type) ? MALE.value :
				StringUtils.equals(type, FEMALE.type) ? FEMALE.value : OTHER.value;
		}
	}
}
